package com.hyd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hyd.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hyd.common.annotation.Log;
import com.hyd.common.core.controller.BaseController;
import com.hyd.common.core.domain.AjaxResult;
import com.hyd.common.enums.BusinessType;
import com.hyd.manage.domain.MedicineStock;
import com.hyd.manage.service.IMedicineStockService;
import com.hyd.common.utils.poi.ExcelUtil;
    import com.hyd.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 药品入库Controller
 *
 * @author hwb
 * @date 2025-02-22
 */
@Api(tags = "药品入库Controller")
@RestController
@RequestMapping("/manage/stock")
public class MedicineStockController extends BaseController
{
    @Autowired
    private IMedicineStockService medicineStockService;

    /**
     * 查询药品入库列表
     */
    @ApiOperation("查询药品入库列表")
    @PreAuthorize("@ss.hasPermi('manage:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineStock medicineStock)
    {
        startPage();
        List<MedicineStock> list = medicineStockService.selectMedicineStockList(medicineStock);
        return getDataTable(list);
    }

    /**
     * 导出药品入库列表
     */
    @ApiOperation("导出药品入库列表")
    @PreAuthorize("@ss.hasPermi('manage:stock:export')")
    @Log(title = "药品入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicineStock medicineStock)
    {
        List<MedicineStock> list = medicineStockService.selectMedicineStockList(medicineStock);
        ExcelUtil<MedicineStock> util = new ExcelUtil<MedicineStock>(MedicineStock.class);
        util.exportExcel(response, list, "药品入库数据");
    }

    /**
     * 获取药品入库详细信息
     */
    @ApiOperation("获取药品入库详细信息")
    @PreAuthorize("@ss.hasPermi('manage:stock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(medicineStockService.selectMedicineStockById(id));
    }

    /**
     * 新增药品入库
     */
    @ApiOperation("新增药品入库")
    @PreAuthorize("@ss.hasPermi('manage:stock:add')")
    @Log(title = "药品入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicineStock medicineStock)
    {
        //设置入库时间
        medicineStock.setStockInDate(DateUtils.getNowDate());
        //设置入库人员
        medicineStock.setOperator(getUsername());
        return toAjax(medicineStockService.insertMedicineStock(medicineStock));
    }

    /**
     * 修改药品入库
     */
    @ApiOperation("修改药品入库")
    @PreAuthorize("@ss.hasPermi('manage:stock:edit')")
    @Log(title = "药品入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicineStock medicineStock)
    {
        return toAjax(medicineStockService.updateMedicineStock(medicineStock));
    }

    /**
     * 删除药品入库
     */
    @ApiOperation("删除药品入库")
    @PreAuthorize("@ss.hasPermi('manage:stock:remove')")
    @Log(title = "药品入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medicineStockService.deleteMedicineStockByIds(ids));
    }

    /**
     * 入库药品
     */
    @ApiOperation("入库药品")
    @PreAuthorize("@ss.hasPermi('manage:stock:store')")
    @Log(title = "入库药品", businessType = BusinessType.UPDATE)
    @PutMapping("/{ids}")
    public AjaxResult store(@PathVariable Long[] ids) {
        return toAjax(medicineStockService.storeMedicineStockByIds(ids));
    }
}